package com.seredius.ui;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSeparator;

public class BaseWindow   implements ActionListener, KeyListener{

	//JFrame
	JFrame main = new JFrame();
	
	
	
	// 생성자
	public BaseWindow() {
		// 메뉴바
		//MenuBar
		JMenuBar menuBar = new JMenuBar();
		
		//Adding the menu
		JMenu fileMenu = new JMenu("File");
		JMenu functionMenu = new JMenu("Function");
		JMenu helpMenu = new JMenu("Help");
		
		//Adding the Menu Item
		JMenuItem addFlight = new JMenuItem("Add Flight");
		
		JMenuItem exit = new JMenuItem("Exit");
		JMenuItem landFlight = new JMenuItem("Land Flight");
		JMenuItem virtualPath = new JMenuItem("Virtual Path");
		JMenuItem flightDetails = new JMenuItem("Flight Details");
		JMenuItem about = new JMenuItem("About ...");
		
		//JPanel
		JPanel pnlButton = new JPanel();
		
		//Buttons
		JButton btnAddFlight = new JButton("Add Flight");
		JButton btnLandFlight = new JButton("Land Flight");
		JButton btnVirtualPath = new JButton("Virtual Path");
		JButton btnFlightDetails = new JButton("Flight Details");
		
	    //Adding to the file menu
	    fileMenu.add(addFlight);
	    fileMenu.add(exit);
	    
	    //Adding to the file action listener
	    addFlight.addActionListener(this);
	    exit.addActionListener(this);
	    
	    //Adding to the function menu
	    functionMenu.add(landFlight);
	    functionMenu.add(virtualPath);
	    functionMenu.add(flightDetails);
	
	
	    //Adding to the help menu
	    helpMenu.add(about);
	
	    exit.add(new JSeparator());
	    flightDetails.add(new JSeparator());
	
	    //Adding the Menus to the Menu Bar
	    menuBar.add(fileMenu);
	    menuBar.add(functionMenu);
	    menuBar.add(helpMenu);
	
	    //FlightInfo setbounds
	    btnAddFlight.setBounds(30, 30, 120, 30);
	    btnLandFlight.setBounds(30, 80, 120, 30);
	    btnVirtualPath.setBounds(30, 130, 120, 30);
	    btnFlightDetails.setBounds(30, 180, 120, 30);
	
	    //JPanel bounds
	    pnlButton.setLayout(null);
	
	
	    //Adding to JFrame
	    pnlButton.add(btnAddFlight);
	    pnlButton.add(btnLandFlight);
	    pnlButton.add(btnVirtualPath);
	    pnlButton.add(btnFlightDetails);
	
	
	    main.add(pnlButton);
	
	    // JFrame properties
	    main.setJMenuBar(menuBar);
	    main.setLayout(null);
	    main.setBackground(Color.red);
	    main.setSize(800, 300);
		
	    main.setTitle("Seredius Master Manager");
	
	    main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    main.setVisible(true);
	    
	    //Adding the actionlistener
	    //btnAddFlight.addActionListener(new AddFlight());
	    //btnLandFlight.addActionListener(new LandFlight());
	}
	
	public static void main(String[] args) {
	    new BaseWindow();
	}
	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		String cmd = e.getActionCommand();
		System.err.println(cmd);
		
		if( cmd.equals("Exit") ){
			//main.isValid = false;
			main.setVisible( false );
			main.dispose();
		}
	}
}